package com.jumi.microservice.controller;

import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.feign.*;
import com.jumi.microservice.material.dto.JmGoodsResponse;
import com.jumi.microservice.material.dto.category.JmCategoryResponse;
import com.jumi.microservice.material.dto.supplier.JmSupplierResponse;
import com.jumi.microservice.material.dto.warehouse.JmWarehouseResponse;
import com.jumi.microservice.stock.api.dto.CommodityStockApplyRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author ssk
 * @create 2020/7/18 10:26
 **/
@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    @Resource
    private JmGoodsClient goodsClient;

    @Resource
    private JmSupplierClient supplierClient;

    @Resource
    private JmStockClient stockClient;

    @Resource
    private JmCategoryClient categoryClient;

    @Resource
    private JmWarehouseClient warehouseClient;

    @Resource
    private JmWarehouseSeqClient seqClient;


    @GetMapping("/findGoodsByName")
    public ResponseResult findGoodsByName(String goodsName) {
        ResponseResult<List<JmGoodsResponse>> data = goodsClient.findAllByName(goodsName);
        return data;
    }

    @GetMapping("/findSupplierByName")
    public ResponseResult findSupplierByName(String supplierName) {
        ResponseResult<List<JmSupplierResponse>> data = supplierClient.findAllByName(supplierName);
        List<JmSupplierResponse> list = data.getData();
        List<Map<String, Object>> rsList = new ArrayList<>();
        for (JmSupplierResponse sup : list) {
            Map<String, Object> map = new HashMap<>();
            map.put("supplierId", sup.getSupplierId());
            map.put("supplierCompanyName", sup.getSupplierCompanyName());
            rsList.add(map);
        }
        return ResponseResult.success(rsList);
    }

    @GetMapping("/findWarehouseById")
    public ResponseResult findWarehouseById(Long warehouseId) {
        ResponseResult<JmWarehouseResponse> data = warehouseClient.findById(warehouseId);
        return data;
    }

    @GetMapping("/findSupplierById")
    public ResponseResult findSupplierById(Long id) {
        ResponseResult<JmSupplierResponse> data = supplierClient.findById(id);
        return data;
    }

    @GetMapping("/say")
    public String sayHello() {
        return "hello";
    }

    @GetMapping("/applyInventory")
    public ResponseResult applyInventory(CommodityStockApplyRequest jmCommodityStockRequest) {
        return null;
    }

    @GetMapping("/findWarehouse")
    public ResponseResult findWarehouse() {
        ResponseResult<List<JmWarehouseResponse>> data = warehouseClient.findAll();
        return data;

    }

    @GetMapping("/findCategory")
    public ResponseResult findCategory() {
        ResponseResult<List<JmCategoryResponse>> data = categoryClient.findAll();
        return data;

    }

    @GetMapping("/findSeqByAreaId")
    public ResponseResult findSeqByAreaId(Long areaId) {
        ResponseResult<List<Map<String, Object>>> data = seqClient.findByAreaId(areaId);
        return data;
    }
}
